<?php
namespace app\common\model\mysql;
use think\Model;

class Category extends Model{
    /*
     * 自动写入时间
     */
    protected $autoWriteTimestamp = true;

    /*
     * @param string $field
     * @return \think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getNormalData($field="*"){
        $where=[
            'status'=>config('status.mysql.table_normal')
        ];
        $order=[
           'sort'=>'desc',
            'id'=>'desc'
        ];
        $result = $this->where($where)->field($field)->order($order)->select();
        return $result;
    }

    /*
     * 获取列表数据
     */
    public function getLists($where,$num=10){
         $order = [
             'sort'=>'desc',
             'id'=>'desc'
         ];
         $result = $this->where('status','<>',config('status.mysql.tabel_delete'))
                 ->order($order)
                 ->where($where)
                 ->paginate($num);
         return $result;
    }

    /*
     * 排序
     */
    public function updateBySort($id,$data){
        $data['update_time'] =  date('Y-m-d H:i:s',time());
        return $this->where(['id'=>$id])->save($data);
    }


}